package com.jml.蚂蚁.netty.普通server;


import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.CharsetUtil;

/**
 * @author:jml
 * @date: 2019/12/24 10:37
 * @description：
 */
public class ServerHandler  extends SimpleChannelInboundHandler {
	
	/**
	 * @Description:服务端接收数据+服务端响应客户端
	 * @param ctx: 服务端响应客户端
	 * @param msg: 服务端接收的数据
	 * @return:void
	 */
	@Override
	protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
		ByteBuf byteBuf = (ByteBuf) msg;
		String request = byteBuf.toString(CharsetUtil.UTF_8);
		System.out.println("request:" + request);
		//
		ctx.writeAndFlush((Unpooled.copiedBuffer("服务端给的响应\n", CharsetUtil.UTF_8)));
	}
}
